<template>
<div>
  <div class="table-data" v-show="tabShow">
    <div class="search-box">
      <el-input size="small" v-model="searchMap.keyword" placeholder="渠道名称"></el-input>
      <el-button size="small" type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
    </div>
    <el-table 
      v-loading="loading"
      element-loading-text="正在加载"
      element-loading-spinner="el-icon-loading" :data="tableData"  style="width:100%" :height="tHeight" class="table-box">
      <el-table-column label="id" prop="id" width="100"></el-table-column>
      <el-table-column label="渠道名称" prop="name"></el-table-column>
      <el-table-column label="渠道类型">
        <template slot-scope="scope">
          <p v-if="scope.row.settle_type==1">储值</p>
          <p v-else>代收款</p>
        </template>
      </el-table-column>
      <el-table-column label="联系人" prop="link_name"></el-table-column>
      <el-table-column label="联系电话" prop="phone"></el-table-column>
      <el-table-column label="可结算金额" prop="settle_valid_amount"></el-table-column>
      <el-table-column label="冻结金额" prop="settle_freeze"></el-table-column>
      <el-table-column label="已结算" prop="settled_amount"></el-table-column>
      <el-table-column label="创建时间" prop="create_time" width="160"></el-table-column>
      <el-table-column label="操作" width="160">
        <template slot-scope="scope">
          <router-link  :to="{name:'channelDetail',query:{id:scope.row.id}}" @click.native="handleDetail()" class="user-detail el-button el-button--primary el-button--mini">结算明细</router-link>
          <!-- <el-button size="mini" type="danger" @click="handleEdit(scope.$index,scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <div class="pages" ref="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10,30,50]"
        :page-size="size"
        layout="total,sizes,prev,pager,next,jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
  <router-view @loadData="loadData"></router-view>
</div>
</template>

<script lang="ts">
import { Component, Vue, Provide,Prop,Watch } from "vue-property-decorator";
// import { State, Getter, Mutation, Action } from "vuex-class";
import settlementApi from "@/api/settlement"
@Component({
  components: { }
})
export default class channelSettlement extends Vue {
  // @Getter("user") getUser: any;
  @Provide() tHeight: number = document.body.offsetHeight - 323;
  @Provide() tableData: any = []; // 表格数据
  @Provide() multipleTable: any = []; // 表格数据
  @Provide() businessTypeList: any = []; // 商家类型
  @Provide() page: number = 1; // 当前page
  @Provide() size: number = 10; // 请求数据的个数 默认5
  @Provide() total: number = 0; // 总数据条数
  @Provide() tabShow: Boolean = true; // 是显示否列表页面
  @Prop({}) tabVisible!: any;
  @Provide() state: boolean = true; // 黑白名单状态
  @Provide() loading: Boolean = true; // 是否显示加载图标
  @Provide() searchMap:any={
    keyword: "",
  }
  @Provide() formData:{
  }={
  }
  @Watch("$route") handleRouteChange(to: any,form:any) {
    if(form.path!='/channelSettlement'){
      this.tabShow=this.tabVisible;
    }
  }
  headClass() {
            return "text-align: center;background:#eef1f6;";
        }
  handleDetail(){
    this.tabShow=false
  }

  created() {
    this.loadData();
    if(this.$route.path!='/channelSettlement'){
      this.tabShow=false
    }
  }

  loadData() {
    settlementApi.channelSettList(this.page,this.size,this.searchMap)
      .then((res: any) => {
        this.tableData=res.data.data.list
        this.total=res.data.data.total
        this.loading=false
    });
  }

  handleSizeChange(val: number): void {
    this.size = val;
    this.page = 1;
    this.loadData();
  }
  handleCurrentChange(val: number): void {
    this.page = val;
    this.loadData();
  }
  handleSearch(): void {
    // 点击搜索
    this.page = 1;
    this.loadData();
  }
}
</script>

<style lang="scss" scoped>
.el-range-editor.el-input__inner{
  margin-right: 10px
}
</style>
